﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPlatformPages.h"
#include "GbmpUiPlatformCommandIds.h"
#include "GbmpControlIds.h"
#include "GcmpCommandState.h"
#include "IUiDocument.h"
#include "GmGbmpUiConfigurationCommandRegister.h"
#include "IPublishConfig.h"
#include "StructureCmdIds.h"
#include "CmdInplaceEditNameDefines.h"

#include "IRibbon.h"
#include "IRibbonPage.h"
#include "IRibbonGroup.h"
#include "IApplication.h"
#include "IMainWindow.h"
#include "ICommandButtonMenuDefinition.h"
#include "ICommandMenuItemDefinition.h"
#include "ICommandButtonDefinition.h"
#include "IPageHandler.h"
#include "GcmpCommandNames.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

namespace
{
    class GbmpModifyPageHandler : public IPageHandler
    {
    public:
        GbmpModifyPageHandler(){}

        virtual bool IsVisible() const override
        {
            return GcmpCommandState::IsInProjectEnvironment() && !GcmpCommandState::IsInAnimationEnvironment();
        }
        virtual bool IsEnabled() const override
        {
            return true;
        }
    };
    //////////////////////////////////////////////////////////////////////////
}

void CmdShowPropertyDialog(gcmp::IUiDocument* pUIDoc);
bool CmdShowTypePropertyDialog(gcmp::IUiDocument* pUIDoc);
void CmdNewFamilyTypeDialog(gcmp::IUiDocument* pUIDoc);

void AddPlatformPages::AddPageGbmpModify()
{
    OwnerPtr<IRibbonPage> opPage = IRibbonPage::Create(ID_PAGE_GBMP_MODIFY, GBMP_TR(L"修改"));
    DBG_WARN_AND_RETURN_VOID_UNLESS(opPage, L"opPage为空",L"GDMPLab",L"2024-03-30");
    opPage->SetPageHandler(TransferOwnership(NEW_AS_OWNER_PTR(GbmpModifyPageHandler)));

    // 修改Group
    {
        // 拾取（允许按面选择、禁止按面选择）
        const std::wstring groupId(L"gbmpModifyGroup");
        OwnerPtr<IRibbonGroup> opModifyGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"修改"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opModifyGroup, L"opModifyGroup为空",L"GDMPLab",L"2024-03-30");
        {
            const std::wstring menuId = L"gbmpModifyMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opBottonMenuDef = ICommandButtonMenuDefinition::Create(menuId, ID_CMD_GBMP_MODIFY, GBMP_TR(L"修改"), L":/images/modify/拾取.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opBottonMenuDef, L"opBottonMenuDef为空",L"GDMPLab",L"2024-03-30");

            OwnerPtr<ICommandMenuItemDefinition> opAllowSelectButtonDef = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_MODIFY, ID_CMD_GBMP_MODIFY, GBMP_TR(L"允许按面选择"), GBMP_TR(L"允许按面选择"), L"");
            opBottonMenuDef->AddItem(TransferOwnership(opAllowSelectButtonDef));
            
            OwnerPtr<ICommandMenuItemDefinition> opForbidSelectButtonDef = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_MODIFY_FILTER_FACE, ID_CMD_GBMP_MODIFY_FILTER_FACE, GBMP_TR(L"禁止按面选择"), GBMP_TR(L"禁止按面选择"), L"");
            opBottonMenuDef->AddItem(TransferOwnership(opForbidSelectButtonDef));

            opModifyGroup->AddButtonMenu(TransferOwnership(opBottonMenuDef));
            opPage->AddGroup(TransferOwnership(opModifyGroup));
        }
    }

    // 剪切板Group
    {
        // 添加粘贴、剪切、复制按钮
        const std::wstring groupId(L"gbmpClipboardGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"剪切板"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");
        {
            const std::wstring menuId = L"gbmpPasteMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(menuId, L"", GBMP_TR(L"粘贴"), L":/images/modify/粘贴.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");

            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_CLIPBOARD_PASTE, ID_CMD_GBMP_CLIPBOARD_PASTE, GBMP_TR(L"粘贴"), GBMP_TR(L"粘贴"), L":/images/modify/粘贴.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_CLIPBOARD_PASTE_TO_LEVEL, ID_CMD_GBMP_CLIPBOARD_PASTE_TO_LEVEL, GBMP_TR(L"对齐粘贴到标高"), GBMP_TR(L"对齐粘贴到标高"), L":/images/modify/粘贴.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }

            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_CLIPBOARD_CUT, GBMP_TR(L"剪切"), GBMP_TR(L"剪切"), ID_CMD_GBMP_CLIPBOARD_CUT, L":/images/modify/剪切.png", ButtonStyle::IconOnly);
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_CLIPBOARD_COPY, GBMP_TR(L"复制"), GBMP_TR(L"复制"), ID_CMD_GBMP_CLIPBOARD_COPY, L":/images/modify/复制到裁剪板.png", ButtonStyle::IconOnly);
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 通用编辑 Group
    {
        const std::wstring groupId(L"gbmpGeneralEditGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"通用编辑"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_MOVE_SELECTION, GBMP_TR(L"移动"), GBMP_TR(L"移动"), ID_CMD_GBMP_MOVE_SELECTION, L":/images/modify/移动.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_ROTATE_ELEMENT, GBMP_TR(L"旋转"), GBMP_TR(L"旋转"), ID_CMD_GBMP_ROTATE_ELEMENT, L":/images/modify/旋转.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_MIRROR, GBMP_TR(L"镜像"), GBMP_TR(L"镜像"), ID_CMD_GBMP_MIRROR, L":/images/modify/镜像.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_ALIGNMENT, GBMP_TR(L"对齐"), GBMP_TR(L"对齐"), ID_CMD_GBMP_ALIGNMENT, L":/images/modify/对齐.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_COPY, GBMP_TR(L"复制"), GBMP_TR(L"复制"), ID_CMD_GBMP_COPY, L":/images/modify/复制.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {// 阵列 
            const std::wstring ButtonMenuId = L"gbmpPatternMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(ButtonMenuId, ID_CMD_GBMP_LINEAR_PATTERN, GBMP_TR(L"阵列"), L":/images/modify/线性阵列.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_LINEAR_PATTERN, ID_CMD_GBMP_LINEAR_PATTERN, GBMP_TR(L"阵列"), GBMP_TR(L"阵列"), L":/images/modify/线性阵列.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_GBMP_RADIAL_PATTERN, ID_CMD_GBMP_RADIAL_PATTERN, GBMP_TR(L"环阵"), GBMP_TR(L"环阵"), L":/images/modify/环形阵列.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_CUT_ELEMENT, GBMP_TR(L"扣减"), GBMP_TR(L"扣减"), ID_CMD_GBMP_CUT_ELEMENT, L":/images/modify/扣减.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_DELETE_SELECTION, GBMP_TR(L"删除"), GBMP_TR(L"删除"), ID_CMD_GBMP_DELETE_SELECTION, L":/images/modify/删除.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }
    // 线性对象
    {
        const std::wstring groupId(L"gbmpLinearObject");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"线性对象编辑"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_OFFSET, GBMP_TR(L"偏移"), GBMP_TR(L"偏移"), ID_CMD_GBMP_OFFSET, L":/images/modify/偏移.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_TRIM_ELEMENT, GBMP_TR(L"修角"), GBMP_TR(L"修角"), ID_CMD_GBMP_TRIM_ELEMENT, L":/images/modify/修角.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_EXTEND_ELEMENT, GBMP_TR(L"延伸"), GBMP_TR(L"延伸"), ID_CMD_GBMP_EXTEND_ELEMENT, L":/images/modify/延伸裁剪.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }        
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_BREAK_ELEMENT, GBMP_TR(L"打断"), GBMP_TR(L"打断"), ID_CMD_GBMP_BREAK_ELEMENT, L":/images/modify/打断.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CHAMFER_RIGHT_ANGLE, GBMP_TR(L"倒角"), GBMP_TR(L"倒角"), ID_CMD_CHAMFER_RIGHT_ANGLE, L":/images/modify/直角-大.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CHAMFER_FILLET, GBMP_TR(L"圆角"), GBMP_TR(L"圆角"), ID_CMD_CHAMFER_FILLET, L":/images/modify/圆角-大.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }
    //取消连接
    {
        const std::wstring groupId(L"gmCancelJoin");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"取消连接"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_CANCEL_STRUCTURE_JOIN, GBMP_TR(L"取消连接"), GBMP_TR(L"取消连接"), ID_CMD_GBMP_CANCEL_STRUCTURE_JOIN, L":images/structure/取消连接.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }
    // 楼板、筏板、板洞
    {
        const std::wstring groupId(L"gmEditFloorProfileGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"编辑楼板"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_EDIT_STRUCTURE_FLOOR, GBMP_TR(L"编辑楼板"), GBMP_TR(L"编辑楼板"), ID_CMD_EDIT_STRUCTURE_FLOOR, L":images/structure/楼板轮廓.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    {
        const std::wstring groupId(L"gmEditStructurePlateHoleProfileGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"编辑板洞"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_EDIT_STRUCTURE_PLATE_HOLE, GBMP_TR(L"编辑板洞"), GBMP_TR(L"编辑板洞"), ID_CMD_EDIT_STRUCTURE_PLATE_HOLE, L":images/structure/楼板轮廓.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    {
        const std::wstring groupId(L"gmEditFoundationProfileGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"编辑筏板"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_EDIT_RAFT_FOUNDATION, GBMP_TR(L"编辑筏板"), GBMP_TR(L"编辑筏板"), ID_CMD_EDIT_RAFT_FOUNDATION, L":images/structure/编辑筏板.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    {
        const std::wstring groupId(L"gmEditRoofProfileGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"编辑屋顶"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_EDIT_STRUCTURE_ROOF, GBMP_TR(L"编辑屋顶"), GBMP_TR(L"编辑屋顶"), ID_CMD_EDIT_STRUCTURE_ROOF, L":images/structure/楼板轮廓.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 在位编辑
    {
        const std::wstring groupId(L"gmEditInplaceCreateInstanceGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"在位编辑"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_ENTER_INPLACE_CREATE_MODE, GBMP_TR(L"在位创建"), GBMP_TR(L"在位创建"), ID_CMD_ENTER_INPLACE_CREATE_MODE, L":/images/family_inplace_creation.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_ENTER_INPLACE_EDIT_MODE, GBMP_TR(L"在位编辑"), GBMP_TR(L"在位编辑"), ID_CMD_ENTER_INPLACE_EDIT_MODE, L":/images/family_inplace_editing.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        //{
        //    OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_SHOW_INPLACE_EDIT_PROJECT_MODEL_VIEW_DLG, GBMP_TR(L"显示项目视图面板"), GBMP_TR(L"显示项目视图面板"), ID_CMD_SHOW_INPLACE_EDIT_PROJECT_MODEL_VIEW_DLG, L":/images/work_plane.png");
        //    opGroup->AddButton(TransferOwnership(opButtonDef));
        //}

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 插入Group
    {
        const std::wstring groupId(L"gmFamilyLoadTargetGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"构件"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_DRAW_LOAD_FAMILY, GBMP_TR(L"载入构件"), GBMP_TR(L"载入构件文件"), ID_CMD_DRAW_LOAD_FAMILY, L":/images/family_loading.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // CAD缩放
    {
        const std::wstring groupId(L"gmEditCADGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"CAD编辑"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_SCALE_CAD, GBMP_TR(L"CAD缩放"), GBMP_TR(L"CAD缩放"), ID_CMD_GBMP_SCALE_CAD, L":/images/family_inplace_creation.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");
    pRibbon->AddPage(TransferOwnership(opPage));
}
